<!DOCTYPE html>
<html>
<head>
    <title>高德地图示例</title>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=55d42a4e6c68def2d0b482432b47fa1d"></script>
</head>
<body>
    <div id="map-container" style="width: 600px; height: 400px;"></div>
    <script type="text/javascript">
        var map = new AMap.Map('map-container', {
            resizeEnable: true,
            center: [116.397428, 39.90923], // 初始化地图中心点
            zoom: 13 // 初始化地图层级
        });

        // 调用Django视图获取地址信息
        function getAddress(location) {
            var xhr = new XMLHttpRequest();
            xhr.open('GET', '/get-address/?location=' + location, true);
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    var response = JSON.parse(xhr.responseText);
                    if (response.status === '1') {
                        alert('地址：' + response.regeocode.formatted_address);
                    } else {
                        alert('获取地址失败');
                    }
                }
            };
            xhr.send();
        }

        // 示例：点击地图获取地址
        AMap.event.addListener(map, 'click', function(e) {
            getAddress(e.lnglat.getLng() + ',' + e.lnglat.getLat());
        });
    </script>
</body>
</html>
